import { Engine } from "../Engine";
import { Geometry } from "./Geometry";
import { process } from "../process/worker/process";
import { any, has, } from "../core/logic";
import { Buffer } from "../gpu/types/Buffer";
/**
 * 点状几何体。
 * @class
 * @memberof w.geometry
 */
class PointsGeometry extends Geometry {
    /**
     * 创建材质
     * @constructor
     * @param {*} opts
     * @param {string} opts.name 【可选】名称。
     */
    constructor(opts = {}, share) {
        super(opts, share);
        this._cameraView = any(opts.cameraView, "all"); //相机的视图,缺省使用vp矩阵。
        this.type = "PointGeometry";
        this.geometryType = "PointsGeometry";
        this._hash = "";
        this.size = opts.size
        this.rotation = opts.rotation;
        this.opacity = opts.opacity;
        this.visible = opts.visible;
        this.buffer = opts.buffer;
        this.particle = opts.particle;
        if (opts.autoUpdate === undefined) {
            this.autoUpdate = true;
        } else {
            this.autoUpdate = opts.autoUpdate;
        }
        this.update();
    }

    set position(v) {
        if (!has(v)) {
            return;
        }
        this._position = v;
        this.addParam("position");
        if (this.has("position")) {
            this.initVertex(this.position, "position", 3, "instance");
        }
        this.update();
        return this;
    }

    get position() {
        return this._position;
    }
    set rotation(v) {
        if (!has(v)) {
            return;
        }
        this._rotation = v;
        this.addParam("rotation");
        if (this.has("rotation")) {
            this.initVertex(this.rotation, "rotation", 1, "instance");
        }
        this.update();
        return this;
    }

    get rotation() {
        return this._rotation;
    }
    set color(v) {
        if (!has(v)) {
            return;
        }
        this._color = v;
        this.addParam("color");
        if (this.has("color")) {
            this.initVertex(this.color, "color", 3, "instance");
        }
        this.update();
        return this;
    }

    get color() {
        return this._color;
    }
    set size(v) {
        if (!has(v)) {
            return;
        }
        this._size = v;
        this.addParam("size");
        if (this.has("size")) {
            this.initVertex(this.size, "size", 1, "instance");
        }
        this.update();
        return this;
    }

    get size() {
        return this._size;
    }
    set opacity(v) {
        if (!has(v)) {
            return;
        }
        this._opacity = v;
        this.addParam("opacity");
        if (this.has("opacity")) {
            this.initVertex(this.opacity, "opacity", 1, "instance");
        }
        this.update();
        return this;
    }

    get opacity() {
        return this._opacity;
    }
    set visible(v) {
        if (!has(v)) {
            return;
        }
        this._visible = v;
        this.addParam("visible");
        if (this.has("visible")) {
            this.initVertex(this.visible, "visible", 1, "instance");
        }
        this.update();
        return this;
    }

    get visible() {
        return this._visible;
    }
    set buffer(v) {
        if (!has(v)) {
            return;
        }
        this._buffer = v;
        this.addParam("buffer");
        if (this.has("buffer")) {
            this.initVertex(this.buffer, "buffer", 1, "instance");
        }
        this.update();
        return this;
    }

    get buffer() {
        return this._buffer;
    }
    set particle(v) {
        if (!has(v)) {
            return;
        }
        this._particle = v;
        let particleParameter = this.getParam("particle");
        if (!particleParameter) {
            particleParameter = new Buffer({
                name: "particle",
                type: "read-only-storage",
                buffer:v,
                visibility:GPUShaderStage.VERTEX
            })
            this.addParam("particle", particleParameter);
        } else {
                particleParameter.buffer(v);
        }
        particleParameter.state = true;
        this.update();
        return this;
    }

    get particle() {
        return this._particle;
    }


}

export { PointsGeometry };
